package chpt04.shapes;

public class Circle extends Shape {

	private double radius;  // 半径
	
	public Circle() {
	}
	
	public Circle(double radius) {
		this.radius = radius;
	}
	

	public Circle(int id, int x, int y, double radius) {
		super(id, x, y);
		this.radius = radius;
	}

	public double getRadius() {
		return radius;
	}
	
	public void setRadius(double radius) {
		this.radius = radius;
	}
	
	@Override
	public double getArea() {
		return Math.PI*radius*radius;
	}
	@Override
	public double getPerimeter() {
		return 2*Math.PI*radius;
	}
	
	
	
	@Override
	public String toString() {
		return "Circle : 半径 = " + radius;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		long temp;
		temp = Double.doubleToLongBits(radius);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Circle other = (Circle) obj;
		if (Double.doubleToLongBits(radius) != 
				Double.doubleToLongBits(other.radius))
			return false;
		return true;
	}

	
	public static void main(String[] args) {
		Circle c1 = new Circle(Double.NaN);
		Circle c2 = new Circle(Double.NaN);
		System.out.println(c1);
		System.out.println(c1.equals(c2));
		Circle c3 = new Circle(5.6);
		Circle c4 = new Circle(1, 3, 5, 5.6);
	}

}
